import type { MessageInstance } from "antd/es/message/interface";
import type { ModalStaticFunctions } from "antd/es/modal/confirm";
import type { NotificationInstance } from "antd/es/notification/interface";
import React from "react";
import { History } from 'history'
export interface ILoginOptions {
    username: string;
    password: string;
    captcha: string;
    captchaKey: string;
    returnUrl: string;
}
export interface ICurrentUser {
    username: string;
    id: string;
    uid: number;
    welcome_link: string;
    avatar?: string;
}
export interface IMenu {
    title: string;
    icon: string;
    link: string;
    main: string;
}
export interface NavigationTo {
    (path: string, params?: any): void;
}
export interface IContext {
    width?: number;
    height?: number;
    login?: (options: ILoginOptions) => Promise<void>;
    getPageSetting?: (path: string) => Promise<any>;
    captcha?: (width?: number, height?: number) => Promise<{ data: string, hashkey: string }>;
    currentUser?: ICurrentUser;
    setCurrentUser?: (user: ICurrentUser | null) => void;
    me?: (auto?: boolean) => Promise<void>;
    menus?: IMenu[];
    setMenus?: (menus: IMenu[]) => void;
    fold?: boolean;
    setFold?: (fold: boolean) => void;
    logout?: () => Promise<void>;
    message?: MessageInstance;
    notification?: NotificationInstance;
    modal?: Omit<ModalStaticFunctions, 'warn'>;
    navigate?: NavigationTo;
    setNavigate?: (navigate: NavigationTo) => void;
    history?: History;
}
export const Context = React.createContext<IContext>({})

export function useCtx(): Required<IContext> {
    return React.useContext(Context) as any
}
